package com.atguigu.cos.controller;

import com.atguigu.commonutils.R;
import com.atguigu.cos.service.CosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author shkstart
 * @create 2022-09-17 20:41
 */
@RestController
@RequestMapping("/educos/filecos")
//@CrossOrigin
public class CosController {

    @Autowired
    private CosService cosService;

    //上传头像的方法
    @PostMapping("/upload")
    public R uploadCosFile(@RequestPart MultipartFile file) throws Exception {
        //提前判断uploadFile的图片是否存在
        if (file == null){
            return R.error();
        }

        //上传文件 MultipartFile
        //返回上传到cos的路径
        String url = cosService.uploadFileAvatar(file);
        return R.ok().data("url",url);
    }

}
